package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Person p = new Person("李四",44);
        System.out.println(p);

        //1.加载类对象
        Class cls = Class.forName("reflect.Person");
        //2.通过类对象获取指定的有参构造器：Person(String,int)
        Constructor c = cls.getConstructor(String.class,int.class);
        Object obj = c.newInstance("王五", 66);
        System.out.println(obj);
    }
}
